﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Texture
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Runtime.CompilerServices;
using UnityEngine.Bindings;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine
{
  /// <summary>
  ///   <para>Base class for Texture handling.</para>
  /// </summary>
  [NativeHeader("Runtime/Graphics/Texture.h")]
  [NativeHeader("Runtime/Streaming/TextureStreamingManager.h")]
  [UsedByNativeCode]
  public class Texture : Object
  {
    /// <summary>
    ///   <para>Can be used with Texture constructors that take a mip count to indicate that all mips should be generated.  The value of this field is -1.</para>
    /// </summary>
    public static readonly int GenerateAllMips = -1;

    protected Texture()
    {
    }

    [NativeProperty("GlobalMasterTextureLimit")]
    public static extern int masterTextureLimit { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>How many mipmap levels are in this Texture (Read Only).</para>
    /// </summary>
    public extern int mipmapCount { [NativeName("GetMipmapCount"), MethodImpl(MethodImplOptions.InternalCall)] get; }

    [NativeProperty("AnisoLimit")]
    public static extern AnisotropicFiltering anisotropicFiltering { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Sets Anisotropic limits.</para>
    /// </summary>
    /// <param name="forcedMin"></param>
    /// <param name="globalMax"></param>
    [NativeName("SetGlobalAnisoLimits")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern void SetGlobalAnisotropicFilteringLimits(int forcedMin, int globalMax);

    /// <summary>
    ///   <para>Returns the GraphicsFormat format or color format of a Texture object.</para>
    /// </summary>
    public virtual GraphicsFormat graphicsFormat => GraphicsFormatUtility.GetFormat(this);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern int GetScriptWidth();

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern int GetScriptHeight();

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern TextureDimension GetDimension();

    /// <summary>
    ///   <para>Width of the Texture in pixels (Read Only).</para>
    /// </summary>
    public virtual int width
    {
      get => this.GetScriptWidth();
      set => throw new NotImplementedException();
    }

    /// <summary>
    ///   <para>Height of the Texture in pixels (Read Only).</para>
    /// </summary>
    public virtual int height
    {
      get => this.GetScriptHeight();
      set => throw new NotImplementedException();
    }

    /// <summary>
    ///   <para>Dimensionality (type) of the Texture (Read Only).</para>
    /// </summary>
    public virtual TextureDimension dimension
    {
      get => this.GetDimension();
      set => throw new NotImplementedException();
    }

    internal extern bool isNativeTexture { [NativeName("IsNativeTexture"), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>Whether Unity stores an additional copy of this texture's pixel data in CPU-addressable memory.</para>
    /// </summary>
    public virtual extern bool isReadable { [MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>Texture coordinate wrapping mode.</para>
    /// </summary>
    public extern TextureWrapMode wrapMode { [NativeName("GetWrapModeU"), MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Texture U coordinate wrapping mode.</para>
    /// </summary>
    public extern TextureWrapMode wrapModeU { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Texture V coordinate wrapping mode.</para>
    /// </summary>
    public extern TextureWrapMode wrapModeV { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Texture W coordinate wrapping mode for Texture3D.</para>
    /// </summary>
    public extern TextureWrapMode wrapModeW { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Filtering mode of the Texture.</para>
    /// </summary>
    public extern FilterMode filterMode { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Defines the anisotropic filtering level of the Texture.</para>
    /// </summary>
    public extern int anisoLevel { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>The mipmap bias of the Texture.</para>
    /// </summary>
    public extern float mipMapBias { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    public Vector2 texelSize
    {
      [NativeName("GetTexelSize")] get
      {
        Vector2 ret;
        this.get_texelSize_Injected(out ret);
        return ret;
      }
    }

    /// <summary>
    ///   <para>Retrieve a native (underlying graphics API) pointer to the Texture resource.</para>
    /// </summary>
    /// <returns>
    ///   <para>Pointer to an underlying graphics API Texture resource.</para>
    /// </returns>
    [MethodImpl(MethodImplOptions.InternalCall)]
    public extern IntPtr GetNativeTexturePtr();

    [Obsolete("Use GetNativeTexturePtr instead.", false)]
    public int GetNativeTextureID() => (int) this.GetNativeTexturePtr();

    /// <summary>
    ///   <para>This counter is incremented when the Texture is updated.</para>
    /// </summary>
    public extern uint updateCount { [MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>Increment the update counter.</para>
    /// </summary>
    [MethodImpl(MethodImplOptions.InternalCall)]
    public extern void IncrementUpdateCount();

    [NativeMethod("GetActiveTextureColorSpace")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern int Internal_GetActiveTextureColorSpace();

    internal ColorSpace activeTextureColorSpace
    {
      [VisibleToOtherModules(new string[] {"UnityEngine.UIElementsModule", "Unity.UIElements"})] get
      {
        return this.Internal_GetActiveTextureColorSpace() == 0 ? ColorSpace.Linear : ColorSpace.Gamma;
      }
    }

    [NativeMethod("GetStoredColorSpace")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern TextureColorSpace Internal_GetStoredColorSpace();

    /// <summary>
    ///   <para>Returns true if the texture pixel data is in sRGB color space (Read Only).</para>
    /// </summary>
    public bool isDataSRGB => this.Internal_GetStoredColorSpace() == TextureColorSpace.sRGB;

    /// <summary>
    ///   <para>The hash value of the Texture.</para>
    /// </summary>
    public Hash128 imageContentsHash
    {
      get
      {
        Hash128 ret;
        this.get_imageContentsHash_Injected(out ret);
        return ret;
      }
      set => this.set_imageContentsHash_Injected(ref value);
    }

    /// <summary>
    ///         <para>The total amount of Texture memory that Unity would use if it loads all Textures at mipmap level 0.
    /// 
    /// This is a theoretical value that does not take into account any input from the streaming system or any other input, for example when you set the`Texture2D.requestedMipmapLevel` manually.
    /// 
    /// To see a Texture memory value that takes inputs into account, use `desiredTextureMemory`.
    /// 
    /// `totalTextureMemory` only includes instances of Texture2D and CubeMap Textures. This value does not include any other Texture types, or 2D and CubeMap Textures that Unity creates internally.</para>
    ///       </summary>
    public static extern ulong totalTextureMemory { [FreeFunction("GetTextureStreamingManager().GetTotalTextureMemory"), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///         <para>The total size of the Textures, in bytes, that Unity loads if there were no other constraints. Before Unity loads any Textures, it applies the which reduces the loaded Texture resolution if the Texture sizes exceed its value. The desiredTextureMemory value takes into account the mipmap levels that Unity has requested or that you have set manually.
    /// 
    /// For example, if Unity does not load a Texture at full resolution because it is far away or its requested mipmap level is greater than 0,  Unity reduces the desiredTextureMemory value to match the total memory needed.
    /// 
    /// The desiredTextureMemory value can be greater than the Texture.targetTextureMemory value.
    ///                 </para>
    ///       </summary>
    public static extern ulong desiredTextureMemory { [FreeFunction("GetTextureStreamingManager().GetDesiredTextureMemory"), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>The total amount of Texture memory that Unity allocates to the Textures in the scene after it applies the and finishes loading Textures. `targetTextureMemory`also takes mipmap streaming settings into account. This value only includes instances of Texture2D and CubeMap Textures. This value does not include any other Texture types, or 2D and CubeMap Textures that Unity creates internally.</para>
    /// </summary>
    public static extern ulong targetTextureMemory { [FreeFunction("GetTextureStreamingManager().GetTargetTextureMemory"), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>The amount of memory that all Textures in the scene use.</para>
    /// </summary>
    public static extern ulong currentTextureMemory { [FreeFunction("GetTextureStreamingManager().GetCurrentTextureMemory"), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>The amount of memory Unity allocates for non-streaming Textures in the scene. This only includes instances of Texture2D and CubeMap Textures. This does not include any other Texture types, or 2D and CubeMap Textures that Unity creates internally.</para>
    /// </summary>
    public static extern ulong nonStreamingTextureMemory { [FreeFunction("GetTextureStreamingManager().GetNonStreamingTextureMemory"), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>How many times has a Texture been uploaded due to Texture mipmap streaming.</para>
    /// </summary>
    public static extern ulong streamingMipmapUploadCount { [FreeFunction("GetTextureStreamingManager().GetStreamingMipmapUploadCount"), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>Number of renderers registered with the Texture streaming system.</para>
    /// </summary>
    public static extern ulong streamingRendererCount { [FreeFunction("GetTextureStreamingManager().GetStreamingRendererCount"), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>Number of streaming Textures.</para>
    /// </summary>
    public static extern ulong streamingTextureCount { [FreeFunction("GetTextureStreamingManager().GetStreamingTextureCount"), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>The number of non-streaming Textures in the scene. This includes instances of Texture2D and CubeMap Textures. This does not include any other Texture types, or 2D and CubeMap Textures that Unity creates internally.</para>
    /// </summary>
    public static extern ulong nonStreamingTextureCount { [FreeFunction("GetTextureStreamingManager().GetNonStreamingTextureCount"), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>Number of streaming Textures with outstanding mipmaps to be loaded.</para>
    /// </summary>
    public static extern ulong streamingTexturePendingLoadCount { [FreeFunction("GetTextureStreamingManager().GetStreamingTexturePendingLoadCount"), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>Number of streaming Textures with mipmaps currently loading.</para>
    /// </summary>
    public static extern ulong streamingTextureLoadingCount { [FreeFunction("GetTextureStreamingManager().GetStreamingTextureLoadingCount"), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>This function sets mipmap streaming debug properties on any materials that use this Texture through the mipmap streaming system.</para>
    /// </summary>
    [FreeFunction("GetTextureStreamingManager().SetStreamingTextureMaterialDebugProperties")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern void SetStreamingTextureMaterialDebugProperties();

    /// <summary>
    ///   <para>Force streaming Textures to load all mipmap levels.</para>
    /// </summary>
    public static extern bool streamingTextureForceLoadAll { [FreeFunction(Name = "GetTextureStreamingManager().GetForceLoadAll"), MethodImpl(MethodImplOptions.InternalCall)] get; [FreeFunction(Name = "GetTextureStreamingManager().SetForceLoadAll"), MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>This property forces the streaming Texture system to discard all unused mipmaps instead of caching them until the Texture is exceeded. This is useful when you profile or write tests to keep a predictable set of Textures in memory.</para>
    /// </summary>
    public static extern bool streamingTextureDiscardUnusedMips { [FreeFunction(Name = "GetTextureStreamingManager().GetDiscardUnusedMips"), MethodImpl(MethodImplOptions.InternalCall)] get; [FreeFunction(Name = "GetTextureStreamingManager().SetDiscardUnusedMips"), MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Allow Unity internals to perform Texture creation on any thread (rather than the dedicated render thread).</para>
    /// </summary>
    public static extern bool allowThreadedTextureCreation { [FreeFunction(Name = "Texture2DScripting::IsCreateTextureThreadedEnabled"), MethodImpl(MethodImplOptions.InternalCall)] get; [FreeFunction(Name = "Texture2DScripting::EnableCreateTextureThreaded"), MethodImpl(MethodImplOptions.InternalCall)] set; }

    [MethodImpl(MethodImplOptions.InternalCall)]
    internal extern ulong GetPixelDataSize(int mipLevel, int element = 0);

    [MethodImpl(MethodImplOptions.InternalCall)]
    internal extern ulong GetPixelDataOffset(int mipLevel, int element = 0);

    internal TextureColorSpace GetTextureColorSpace(bool linear)
    {
      return linear ? TextureColorSpace.Linear : TextureColorSpace.sRGB;
    }

    internal TextureColorSpace GetTextureColorSpace(GraphicsFormat format)
    {
      return this.GetTextureColorSpace(!GraphicsFormatUtility.IsSRGBFormat(format));
    }

    internal bool ValidateFormat(RenderTextureFormat format)
    {
      if (SystemInfo.SupportsRenderTextureFormat(format))
        return true;
      Debug.LogError((object) string.Format("RenderTexture creation failed. '{0}' is not supported on this platform. Use 'SystemInfo.SupportsRenderTextureFormat' C# API to check format support.", (object) format.ToString()), (Object) this);
      return false;
    }

    internal bool ValidateFormat(TextureFormat format)
    {
      if (SystemInfo.SupportsTextureFormat(format) || GraphicsFormatUtility.IsCompressedTextureFormat(format) && GraphicsFormatUtility.CanDecompressFormat(GraphicsFormatUtility.GetGraphicsFormat(format, false)))
        return true;
      Debug.LogError((object) string.Format("Texture creation failed. '{0}' is not supported on this platform. Use 'SystemInfo.SupportsTextureFormat' C# API to check format support.", (object) format.ToString()), (Object) this);
      return false;
    }

    internal bool ValidateFormat(GraphicsFormat format, FormatUsage usage)
    {
      if (usage != FormatUsage.Render && (format == GraphicsFormat.ShadowAuto || format == GraphicsFormat.DepthAuto))
      {
        Debug.LogWarning((object) string.Format("'{0}' is not allowed because it is an auto format and not an exact format. Use GraphicsFormatUtility.GetDepthStencilFormat to get an exact depth/stencil format.", (object) format.ToString()), (Object) this);
        return false;
      }
      if (SystemInfo.IsFormatSupported(format, usage))
        return true;
      Debug.LogError((object) string.Format("Texture creation failed. '{0}' is not supported for {1} usage on this platform. Use 'SystemInfo.IsFormatSupported' C# API to check format support.", (object) format.ToString(), (object) usage.ToString()), (Object) this);
      return false;
    }

    internal UnityException CreateNonReadableException(Texture t)
    {
      return new UnityException(string.Format("Texture '{0}' is not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the Texture Import Settings.", (object) t.name));
    }

    internal UnityException CreateNativeArrayLengthOverflowException()
    {
      return new UnityException("Failed to create NativeArray, length exceeds the allowed maximum of Int32.MaxValue. Use a larger type as template argument to reduce the array length.");
    }

    [SpecialName]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void get_texelSize_Injected(out Vector2 ret);

    [SpecialName]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void get_imageContentsHash_Injected(out Hash128 ret);

    [SpecialName]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void set_imageContentsHash_Injected(ref Hash128 value);
  }
}
